/**
 * @param {number[]} nums
 * @return {number[]}
 */
export var sortArrayByParity = function (nums) {
  let [left, right] = [0, nums.length - 1]
  const ans = new Array(nums.length)
  for (let i = 0; i < nums.length; i++) {
    if (nums[i] % 2 === 0) {
      ans[left] = nums[i]
      left++
    } else {
      ans[right] = nums[i]
      right--
    }
  }
  return ans
}

export var sortArrayByParity2 = function (nums) {
  const ans = []
  for (let i = 0; i < nums.length; i++) {
    if (nums[i] % 2 === 0) ans.unshift(nums[i])
    else ans.push(nums[i])
  }
  return ans
}
